package org.github.manx98.jlibhac.fs;

import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * @author Manx98
 * @version 1.0
 * @since 2022/10/3 0:28
 */
public class BinaryReader extends IStorage {

    private final RandomAccessFile file;
    private final long size;

    /**
     * @param filePath 文件路径
     * @throws IOException 文件读取异常
     */
    public BinaryReader(String filePath) throws IOException {
        super(0);
        this.file = new RandomAccessFile(filePath, "r");
        this.size = this.file.length();
    }

    @Override
    public void read(long offset, byte[] destination, int destOffset, int len) throws IOException {
        this.file.seek(offset);
        this.file.readFully(destination, destOffset, len);
    }

    @Override
    public long getSize() {
        return size;
    }

    @Override
    public void close() throws IOException {
        file.close();
    }
}
